package edu.pku.sei.modeler.uml.commands.compositestructure;

import org.eclipse.draw2d.geometry.Rectangle;

import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.uml.Collaborations.Collaboration;
import edu.pku.sei.modeler.model.uml.InternalStructures.ConnectableElement;
import edu.pku.sei.modeler.model.uml.Kernel.Classifier;
import edu.pku.sei.modeler.uml.commands.NestedElementCreateCommand;

public class ElementNestedInCollaborationCreateCommand extends
		NestedElementCreateCommand {

	Collaboration father;
	Classifier child;
	public ElementNestedInCollaborationCreateCommand(MetaNode node, MetaNode fatherNode,
			Rectangle constraint) {
		super(node, fatherNode, constraint);
	}
	
	@Override
	public boolean canExecute() {
		if (fatherNode.getModelElement() instanceof Collaboration
				&& node.getModelElement() instanceof Classifier)
			return super.canExecute();
		else return false;
	}
	
	@Override
	protected void updateModelElement() {
		this.father = (Collaboration) fatherNode.getModelElement();
		this.child = (Classifier) node.getModelElement();
		
		father.getNestedClassifier().add(child);
	}
	
	@Override
	protected void undoModelElement() {
		father.getNestedClassifier().remove(child);
	}

}
